<template>
  <div style="padding-left:10px; padding-right: 10px; width: calc(100vw - 200px)">
    <div style="margin: 10px 0">
      <el-button  style="margin-left: 5px; background-color: #409EFF; color: white" type="primary" plain @click="exportExcel">导出</el-button>
    </div>
    <!--    搜索区域-->
    <div style="margin: 10px 0">
      <span style="color: #611ee3;font-size: large;">学员名：</span>
      <el-input v-model="search" placeholder="请输入学员名" style="width: 20%" clearable></el-input>
      <el-button style="margin-left: 5px; background-color: #409EFF; color: white" @click="load" plain>查询</el-button>
    </div>
    <el-table
        :data="tableData"
        border
        stripe
        style="width: 100%"
        id="rebateSetTable">
      <el-table-column
          prop="id"
          label="ID"
          sortable>
      </el-table-column>
      <el-table-column
          prop="userName"
          label="学员名">
      </el-table-column>
      <el-table-column
          prop="age"
          label="年龄">
      </el-table-column>
      <el-table-column
          prop="sex"
          label="性别">
      </el-table-column>
      <el-table-column
          prop="address"
          label="地址">
      </el-table-column>
      <el-table-column
          prop="phone"
          label="电话">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>

import FileSaver from "file-saver";
import XLSX from "xlsx";
import request from "@/utils/request";

export default {
  name: 'Home',
  components: {

  },
  data() {
    return {
      form: {},
      search:'',
      dialogVisible:false,
      tableData: [],
      deleteVisible: false,
      coach:{}
    }
  },
  created() {
    let Str =sessionStorage.getItem("coach") || '{}';
    this.coach = JSON.parse(Str);
    this.load();
  },
  methods:{
    exportExcel () {
      var xlsxParam = { raw: true }
      /* generate workbook object from table */
      let wb = XLSX.utils.table_to_book(document.querySelector('#rebateSetTable'),xlsxParam);
      /* get binary string as output */
      let wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' });
      try {
        FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), '用户表.xlsx');
      } catch (e)
      {
        if (typeof console !== 'undefined')
          console.log(e, wbout)
      }
      return wbout
    },
    load(){
      request.get("/api/member/findMember",{
        params: {
          coachId: this.coach.id,
          search: this.search
        }
      }).then(res =>{
        console.log(res);
        this.tableData = res.data
      })
    },

    handleSizeChange(pageSize){//改变当前页面个数
      this.pageSize = pageSize;
      this.load();
    },
    handleCurrentChange(pageNum){//改变当前页码
      this.currentPage4 = pageNum;
      this.load();
    },
  }
}
</script>
